home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / citsrc6K05.lha / oldvexfind.c < prev    next >
C/C++ Source or Header  |  1996-10-13  |  4KB  |  167 lines

  1. /*
  2.  *                              VexFind.c
  3.  *
  4.  * Find the system in VORTEX.SYS.
  5.  */
  6.  
  7. /*
  8.  *                              History
  9.  *
  10.  * 96Sep07  AFP updated to make structures a separate include
  11.  * 90Jul29  HAW Initial creation.
  12.  */
  13.  
  14. /*
  15.  *                              Contents
  16.  *
  17.  */
  18.  
  19. #include "ctdl.h"    /* header file  */
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <ctype.h>
  25. #include <time.h>
  26. #include <proto/exec.h>
  27. #include <dos/dos.h>
  28. #include <pragmas/dos_pragmas.h>
  29. #include "exec/memory.h"
  30. #include "exec/ports.h"
  31. #include "exec/exec.h"
  32. #include "vortex.h"
  33.  
  34.  
  35. #define USAGE   "Usage: VEXFIND \"<system name>\"\n  or\nVEXFIND\n"
  36.  
  37. FILE *vx;
  38. void Find(char *name);
  39. void ShowAll(void);
  40. void ShowRoomInfo(int x);
  41.  
  42. extern CONFIG cfg;
  43. extern rTable *roomTab;                 /* RAM index of rooms           */
  44. extern aRoom  roomBuf;                  /* room buffer                  */
  45. extern FILE   *roomfl;                  /* file descriptor for rooms    */
  46. extern int    thisRoom;                 /* room currently in roomBuf    */
  47.  
  48. char TabRead = FALSE;
  49. /*
  50.  * main()
  51.  *
  52.  * This is the main manager.
  53.  */
  54. int main(int, char **);
  55. int main(argc, argv)
  56. int  argc;
  57. char **argv;
  58. {
  59.     extern char *READ_ANY;
  60.     SYS_FILE filename;
  61.  
  62.     printf("Citadel Vortex Listing %s\n%s\n",VERSION_NAME, COPYRIGHT);
  63.  
  64.     if (argc > 2) {
  65.         printf(USAGE);
  66.         exit(1);
  67.     }
  68.  
  69.     if ((vx = fopen("VORTEX.SYS", READ_ANY)) == NULL) {
  70.         if (!readSysTab(FALSE, TRUE)) {
  71.             printf("Couldn't find anything to work with.\n");
  72.             exit(1);
  73.         }
  74.         TabRead = TRUE;
  75.         makeSysName(filename, "VORTEX.SYS", &cfg.netArea);
  76.         if ((vx = fopen(filename, READ_ANY)) == NULL) {
  77.             printf("Couldn't find a VORTEX.SYS to work with.\n");
  78.             exit(1);
  79.         }
  80.     }
  81.  
  82.     if (argc == 1) ShowAll();
  83.     else Find(argv[1]);
  84. return 0;
  85. }
  86.  
  87. /*
  88.  * ShowAll()
  89.  *
  90.  * This function shows all the systems listed in the vortex list.
  91.  */
  92. void ShowAll()
  93. {
  94.     VtRecord Vtx;
  95.     int i = 0;
  96.  
  97.     while (fread(&Vtx, 1, sizeof Vtx, vx) > 0)
  98.         printf("%3d. %-25s : %s\n", i++, Vtx.Name, Vtx.Id);
  99. }
  100.  
  101. /*
  102.  * Find()
  103.  *
  104.  * This function finds the named system in the vortex list.  First occurrence
  105.  * only.
  106.  */
  107. void Find(char *name)
  108. {
  109.         VtRecord Vtx;
  110.         int i = 0;
  111.  
  112.     if (!TabRead && readSysTab(FALSE, FALSE))   TabRead = TRUE;
  113.  
  114.     while (fread(&Vtx, 1, sizeof Vtx, vx) > 0) {
  115.         if (stricmp(name, Vtx.Name) == 0) {
  116.             printf("%3d. %s\n", i, Vtx.Name);
  117.             ShowRoomInfo(i);
  118.             break;
  119.         }
  120.         i++;
  121.     }
  122. }
  123.  
  124.  
  125.  
  126. /*
  127.  * ShowRoomInfo()
  128.  *
  129.  * This function tries to show which rooms are actually shared.
  130.  */
  131. void ShowRoomInfo(int x)
  132. {
  133.     char temp[10];
  134.     SYS_FILE vortex;
  135.     VORTEX data;
  136.     int room;
  137.     FILE *fd;
  138.  
  139.     if (TabRead) {
  140.         sprintf(temp, "%d.vex", x);
  141.         makeSysName(vortex, temp, &cfg.netArea);
  142.         if ((fd = fopen(vortex, READ_ANY)) != NULL) {
  143.             while (fread(&data, sizeof data, 1, fd) >= 1) {
  144.                 room = data.vRoomNo;
  145.                 if (roomTab[room].rtflags.INUSE &&
  146.                             roomTab[room].rtgen == data.vGen) {
  147.                     printf("%s ", roomTab[room].rtname);
  148.                     printf("Last message is %lu, ", data.vHighest);
  149.                     printf("Date on last message was %s.\n",
  150.                                                 LastOn(data.vLastDate, FALSE));
  151.                 }
  152.             }
  153.             fclose(fd);
  154.         }
  155.     }
  156. }
  157.  
  158. /*
  159.  * crashout()
  160.  *
  161.  * Fatal error handler.
  162.  */
  163. void crashout(char *str)
  164. {
  165.     exit(printf("%s\n", str));
  166. }
  167.